import React from 'react'
import PropTypes from 'prop-types'
import { View, Text, Image, StyleSheet, ImageBackground } from 'react-native'
import { ScaleS, ScaleT, ONE_PIXEL } from 'src/utils/ScreenUtil'
import CustomImage from 'src/components/image/CustomImage'
import { isArrayFn } from 'src/utils/JSTypeUtil'
import CustomButton from 'src/components/button/CustomButton'
import CustomFlatList from 'src/components/custom-flat-list/index'
import EmptyView from 'src/components/empty-view'
import NavigationUtil from 'src/utils/NavigationUtil'

const introPLaceHolder = '这家伙很懒,什么都没写'
export default class SchoolRecruit extends React.PureComponent {
    static propTypes = {
        data: PropTypes.array
    }
    constructor(props) {
        super(props)
        this.state = {
            data: [],
        }
    }

    componentDidMount() {
    }
    //渲染空数据
    _listEmptyComponent = () => {
        return (
            <EmptyView emptyImg={require('src/imgC/home/home_no_data.png')} style={styles.emptyView} firstTip={'暂无相关数据'} />
        )
    }

    _renderItem = ({ item, index }) => {
        // const { data } = this.props
        return (<CustomButton style={[styles.cell]} params={item} key={index} onPress={this.clickItem}>
            <View style={[styles.rightView, item.state === "INLINE" && { opacity: 0.3 }]}>
                <View style={styles.titWrap}>
                    <View style={styles.titWrapLeft}>
                        <Text style={styles.companyName}>{item.name}</Text>
                        <View style={styles.personPropsView}>
                            <Text
                                style={styles.genderText}>主讲：{item.publisher}</Text>

                            <Text
                                style={[styles.genderText, { paddingLeft: ScaleS(15) }]}>{item.state === "INLINE" ? "已下架" : ''}</Text>
                        </View>
                    </View>
                    <CustomImage style={[styles.imgRight, styles.imgContainer]} source={{ uri: item.coverImg }} />
                </View>
                <View style={styles.listContainer}>
                    <CustomButton style={styles.dataMsg} params={item} onPress={this.handlePost}>
                        <Text style={[styles.bottomData]}>{item.postCount}</Text>
                        <Text style={[styles.bottomRightText2]}>职位数</Text>
                    </CustomButton>
                    <CustomButton style={styles.dataMsg} params={item} onPress={this.handleDelivery}>
                        <Text style={[styles.bottomData]}>{item.sendCount}</Text>
                        <Text style={[styles.bottomRightText2]}>投递数</Text>
                    </CustomButton>
                    <CustomButton style={styles.dataMsg} params={item} onPress={this.handleDelivery}>
                        <Text style={[styles.bottomData]}>{item.notDealWithCount}</Text>
                        <Text style={[styles.bottomRightText2]}>未处理</Text>
                    </CustomButton>
                    <CustomButton style={styles.dataMsg} params={item} onPress={this.handleEmployedCount}>
                        <Text style={[styles.bottomData]}>{item.employedCount}</Text>
                        <Text style={[styles.bottomRightText2]}>已录用</Text>
                    </CustomButton>
                </View>
                <View style={styles.bottomTextContainer}>
                    <Text style={styles.bottomText}>{`时间：${item.startTime} - ${item.endTime}`}</Text>
                </View>
            </View>
        </CustomButton>)
    }

    render() {
        const { data } = this.props
        // console.log(data, 'data')
        return (
            <View style={[styles.scene, data.length != 0 ? { marginTop: ScaleS(35) } : { marginTop: ScaleS(0) }]}>
                <CustomFlatList
                    data={data}
                    refreshing={false}
                    renderItem={this._renderItem}
                    showsVerticalScrollIndicator={false}
                    ListEmptyComponent={this._listEmptyComponent()}
                    pullDown={false}
                    pullUp={false}
                />
            </View>
        )
    }

    clickItem = (item) => {
        // if (item.state !== "INLINE") {
        NavigationUtil.navigate('SchoolRecruitment', {
            item
        })
        // }
    }
    handlePost = (item) => {
        // NavigationUtil.navigate('JobPartTime', {
        //     companyId: this.props.companyId
        // })
        NavigationUtil.navigate('SchoolRecruitment', {
            item
        })
    }
    handleDelivery = (item) => {
        NavigationUtil.navigate('SchoolRecruitment', {
            item,
            routerName: '投递'
        })
    }
    handleEmployedCount = (item) => {
        NavigationUtil.navigate('SchoolRecruitment', {
            item,
            routerName: '已录用'
        })
    }
}

const styles = StyleSheet.create({
    scene: {
        flex: 1,
        backgroundColor: 'rgba(255,255,255,1)',
        // marginTop: ScaleS(35),
        minHeight: ScaleS(260),
        flexDirection: 'column'
    },
    cell: {
        width: '100%',
        marginBottom: ScaleS(16),
        flexDirection: "column",
    },
    rightView: {
        // flex: 1,
        marginHorizontal: ScaleS(20),
        borderRadius: ScaleS(10),
        backgroundColor: 'rgba(247, 247, 247, 1)',
        paddingTop: ScaleS(27)
    },
    titWrap: {
        flexDirection: 'row',
        alignItems: 'flex-start',
        justifyContent: 'space-between',
        marginBottom: ScaleS(10),
        marginHorizontal: ScaleS(16),
    },
    titWrapLeft: {
        flexDirection: 'column',
        // height: ScaleS(40),
        justifyContent: 'center',
        marginRight: ScaleS(7)
    },
    companyName: {
        color: 'rgba(60, 60, 60, 1)',
        fontSize: ScaleS(14),
        fontWeight: '500'
    },
    imgContainer: {
        // width: ScaleS(48),
        // height: ScaleS(48),
        marginRight: ScaleS(4),
        borderRadius: ScaleS(10),
        // borderColor: '#ABABAB',
        // borderWidth: 1,
        // borderStyle: 'solid',
        shadowRadius: ScaleS(5),
        shadowOpacity: 0.7,
        shadowColor: '#DEDEDE',
        shadowOffset: {
            width: 0,
            height: 0
        }
    },
    imgRight: {
        width: ScaleS(48),
        height: ScaleS(48),
        resizeMode: 'cover',
        borderRadius: ScaleS(10)
    },
    personPropsView: {
        flexDirection: 'row',
        alignItems: 'center',
        marginTop: ScaleS(8)
    },
    genderText: {
        color: 'rgba(153,153,153,1)',
        fontSize: ScaleT(12),
        fontWeight: '400'
    },
    listContainer: {
        flexDirection: "row",
        // marginTop: ScaleS(16),
        // marginHorizontal: ScaleS(20),
        // marginTop: ScaleS(30),
        marginBottom: ScaleS(16),
        marginHorizontal: ScaleS(16),
    },
    dataMsg: {
        // minWidth: ScaleS(48),
        // height: ScaleS(48),
        // lineHeight: ScaleS(43),
        flexDirection: "column",
        marginRight: ScaleS(32),
        // borderColor: 'red',
        // borderWidth: ScaleS(1),
        // borderStyle: "solid",

    },
    bottomRightText2: {
        fontSize: ScaleT(11),
        color: 'rgba(153, 153, 153, 1)',
        fontWeight: "400"
    },
    bottomData: {
        fontWeight: "600",
        color: "rgba(60, 60, 60, 1)",
        fontSize: ScaleT(16),
        paddingBottom: ScaleS(8),
    },
    bottomTextContainer: {
        borderTopColor: '#f1f1f1',
        // borderTopColor: 'rgba(151, 151, 151, 0.3)',
        borderStyle: "solid",
        borderTopWidth: ONE_PIXEL,
    },
    bottomText: {
        color: 'rgba(204, 204, 204, 1)',
        fontSize: ScaleT(11),
        paddingTop: ScaleS(11),
        paddingBottom: ScaleS(11),
        fontWeight: "400",
        marginHorizontal: ScaleS(16),
    },
    emptyView: {
        flex: 1,
        backgroundColor: '#fff',
        minHeight: ScaleS(250),
        paddingTop: ScaleS(80)
    },
})
